<template>
  <!--表格渲染-->
  <DataGridTable
    v-loading="loading"
    :sup_this="sup_this"
    :data="data.rtnList"
    :show-page="false"
    :multi-select="false"
    :show-row-number="true"
    :all-define-columns="['userAccount','userName','phone','email','userStatus','enableFlag','createDate']"
    grid-id="roleUserListGridId"
    row-key="id">
    <el-table-column v-if="checkPermission(['SYS_ADMIN','COMMON_ADMIN','ROLE_ALL','ROLE_DELETE'])" label="操作" width="130px" align="center">
      <template slot-scope="scope">
        <el-popover
          v-permission="['SYS_ADMIN','COMMON_ADMIN','ROLE_ALL','ROLE_DELETE']"
          :ref="scope.row.relId"
          placement="top"
          width="180">
          <p>确定要移除吗？</p>
          <div style="text-align: right; margin: 0">
            <el-button size="mini" type="text" @click="$refs[scope.row.relId].doClose()">取消</el-button>
            <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.relId)">确定</el-button>
          </div>
          <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column slot="userAccount" prop="userAccount" label="用户账号"/>
    <el-table-column slot="userName" prop="userName" label="名称" width="150px" />
    <el-table-column slot="phone" prop="phone" label="电话" width="200px" />
    <el-table-column slot="email" prop="email" label="邮件" width="200px" />
    <el-table-column slot="userStatus" prop="userStatus" label="用户状态" align="center">
      <template slot-scope="scope">
        <div v-for="item in dicts.user_status" :key="item.id">
          <el-tag v-if="scope.row.userStatus.toString() === item.dictCode" :type="scope.row.userStatus === 'UNLOCK' ? '' : 'info'">{{ item.dictName }}</el-tag>
        </div>
      </template>
    </el-table-column>
    <el-table-column slot="enableFlag" prop="enableFlag" label="有效" align="center">
      <template slot-scope="scope">
        <div v-for="item in dicts.enable_flag" :key="item.id">
          <el-tag v-if="scope.row.enableFlag.toString() === item.dictCode" :type="scope.row.enableFlag === 'Y' ? '' : 'info'">{{ item.dictName }}</el-tag>
        </div>
      </template>
    </el-table-column>
    <el-table-column slot="createDate" prop="createDate" label="创建日期" width="200px">
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.createDate) }}</span>
      </template>
    </el-table-column>
  </DataGridTable>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { deleteRoleUser, findUserByRoleIdUrl } from '@/api/system/role'
import { parseTime } from '@/utils/index'

export default {
  mixins: [initData],
  dictTypes: ['user_status', 'enable_flag'],
  props: {
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      delLoading: false,
      roleId: ''
    }
  },
  created() {
    this.pageCount = false
    this.url = findUserByRoleIdUrl()
  },
  methods: {
    parseTime,
    checkPermission,
    loadData() {
      this.init()
    },
    async beforeInit() {
      this.paramBean.id = this.roleId
      return true
    },
    subDelete(relId) {
      this.delLoading = true
      const data = { busMainData: { roleUserVOList: [{ id: relId }] }}
      deleteRoleUser(data).then(res => {
        this.delLoading = false
        this.$refs[relId].doClose()
        this.init()
      }).catch(err => {
        this.delLoading = false
        this.$refs[relId].doClose()
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>
</style>
